<template>
    <div class="applyList applyOprRecord">
        <rui-page :defines="defines" :has-card-box="false">
            <!-- 查询条件 -->
            <rui-query :label-width="100"
                       isApplyQuery
                       ref="oprRecordForm"
                       :query="queryData"
                       :query-rows="searchFormOptions"
                       :more-rows="searchMoreOptions">
            </rui-query>
            <div class="table-card">
                <div class="btn-status flex flex-between">
                    <div class="loanApplyBtn">
                        <Button class="btn" size="default" @click.native="refresh()">刷新</Button>
                    </div>
                </div>
                <!--        <Row>-->
                <!--            <Button @click.native="refresh()" icon="ios-refresh">刷新</Button>-->
                <!--        </Row>-->
                <rui-table
                    :defineId="'applyOprRecordDefines'"
                    :fixed-right="['action']"
                    :showIndex="false"
                    :select="false"
                    :columns="oprRecordColumns"
                    :slots="[{key:'action',slot:'action'}]"
                    @loadDatas="queryData"
                    ref-query="oprRecordForm"
                    ref="oprRecordTable"
                    :border="false"
                >
<!--                    <template slot="action" slot-scope="{ row,index }">-->
<!--                        <Button v-if="$store.getters.permissions['apply_formal_reconsideration']"  @click="edit(row)" type="primary"-->
<!--                                :disabled="row.applyStatusForReconsider!='06'">-->
<!--                            正式复议-->
<!--                        </Button>-->
<!--                    </template>-->
                </rui-table>
            </div>
            <!--详情-->
            <Modal v-model="detailsOprRecordModalVisible"
                   :title="detailsReConsiderTitle"
                   :width="1100"
                   :mask-closable="false">
                <rui-form :form-options="detailsOprRecordFormOptions"
                          ref="detailsRecordForm">
                </rui-form>
                <div slot="footer">
                    <Button size="small" type="info" @click="detailsOprRecordModalVisible = false"
                            icon="ios-backspace-outline">返回
                    </Button>
                </div>
            </Modal>
        </rui-page>
    </div>
</template>
<script>
    import applyOprRecordDefines from "../../api/apply-opr-record/applyOprRecordDefines";
    import {
        searchOprInfoForReconsider,
        updateDelFlag,
        updateOprRecordInfo
    } from "../../api/apply-opr-record/applyOprRecord";
    import {deepClone} from "../../../../libs/utils/ObjectClone";

    export default {
        mounted() {
            let obj = this.afs.getPageParams(this);
            if (obj) {
                if (obj.flag == "home") {
                    if (obj.applyStatusForReconsider) {
                        let param = {
                            condition: {
                                applyNo: "",
                                applyStatusForReconsider: obj.applyStatusForReconsider,
                                custName: "",
                            },
                            pageNumber: 1,
                            pageSize: 10
                        }
                        this.queryData(param)
                    }
                } else {
                    this.refresh();
                }
            } else {
                this.refresh();
            }
            window.details = this.details;
        },
        data() {
            return {
                query: {
                    pageNumber: 1,
                    pageSize: 10,
                    condition: {
                        custName: '',
                        applyNo: '',
                        applyStatusForReconsider: [],
                        startDate: '',
                        endDate: ''
                    }
                },
                detailsOprRecordModalVisible: false,
                detailsReConsiderTitle: "复议详情",
                //查询条件字段
                searchFormOptions: [
                    {
                        //isGroup: false,
                        defineId: "applyOprRecordDefines",
                        fields: ["key"],
                    }
                ],
                searchMoreOptions: [
                    {
                        isGroup: false,
                        defineId: "applyOprRecordDefines",
                        fields: ["applyNo", "custName", "applyStatusForReconsider", "applyTime"],
                    },
                ],
                //显示
                oprRecordColumns: [
                    "custName", "applyNo", "applyStatusForReconsider", "orderApplyStatus", "approveRemarks", "approveDate", "createTime", "createBy", "action"
                ],
                //详情窗口显示字段
                detailsOprRecordFormOptions: [
                    {
                        isGroup: false,
                        groupName: '复议详情',
                        grids: [
                            {
                                defineId: "applyOprRecordDefines",
                                span: 8,
                                fields: ["custName", "applyNo", "createTime", "createBy"]
                            },
                            {
                                defineId: "applyOprRecordDefines",
                                span: 8,
                                fields: ["applyStatusForReconsider", "approveRemarks", "approveDate"]
                            },
                        ]
                    },
                ],
            }
        },
        watch: {
            '$route'(to, from) {
                if (from.path.indexOf("report-edit") > -1) {
                    this.refresh();
                }
            }
        },
        methods: {
            //查询
            queryData(queryData) {
                if (queryData.condition.applyType == '') {
                    queryData.condition.applyType = null;
                }
                if (queryData.condition.applyStatusForReconsider == '' || queryData.condition.applyStatusForReconsider == null) {
                    this.query.condition.applyStatusForReconsider = null;
                } else {
                    this.query.condition.applyStatusForReconsider = [queryData.condition.applyStatusForReconsider];
                }
                if (typeof queryData.condition.applyTime != "undefined") {
                    this.query.condition.startDate = queryData.condition.applyTime[0];
                    this.query.condition.endDate = queryData.condition.applyTime[1];
                }
                if(queryData.condition){

                    this.query.condition.key = queryData.condition.key;
                }
                this.query.pageSize = queryData.pageSize;
                this.query.pageNumber = queryData.pageNumber;
                this.query.condition.custName = queryData.condition.custName;
                this.query.condition.applyNo = queryData.condition.applyNo;
                console.log(this.query);
                searchOprInfoForReconsider(this.query).then(res => {
                    if (res.code === "0000") {
                        if(typeof res.data!=="undefined"){
                            let {records, total} = res.data;
                            this.$refs.oprRecordTable.updateTableData(records, total);
                        }else{
                            this.$refs.oprRecordTable.updateTableData([], 0);
                        }
                    }
                });
            },
            edit(row) {
                let turn = "apply-report-edit" + row.applyNo;
                this.afs.newTab(this, 'projects/afs-apply/pages/apply-report/personal/index', '复议-订单编辑', 'ios-add',
                    {applyNo: row.applyNo, diffType: "edit"}, turn, [], true);
            },
            //详情弹窗
            details(row) {
                this.detailsOprRecordModalVisible = true;
                this.$refs.detailsRecordForm.resetFrom();
                this.$refs.detailsRecordForm.updateFormData(deepClone(row));
                this.$refs.detailsRecordForm.setAllFieldReadOnly(true);
            },
            // 点击修改保存，调用update，进行数据更新
            update() {
                updateOprRecordInfo(this.$refs.oprEditRecordForm.getFormData()).then(res => {
                    if (res.code === "0000") {
                        this.$Message.success("修改成功");
                        this.refresh();
                        // this.editOprRecordModalVisible = false;
                    }
                });
            },
            // 删除
            deleteRow(v) {
                this.$Modal.confirm({
                    title: "确认删除",
                    content: "您确认要删除" + v.custName + "?",
                    onOk: () => {
                        updateDelFlag(v).then(res => {
                            if (res.code === "0000") {
                                this.$Message.success("删除成功");
                                this.refresh();
                            }
                        });
                    },
                });
            },
            //刷新
            refresh() {
                this.$refs['oprRecordTable'].reloadData();
            },
        },

        computed: {
            defines() {
                return [{id: "applyOprRecordDefines", fields: applyOprRecordDefines}];
            }
        },
    }
</script>
<style lang="less" scoped>
    @import "../../assets/css/applyList.less";
</style>
